﻿package Server.AHMJ.HQMJ;

import java.util.Random;

import Server.Model.Base.IServerUserItem;

public class Constants {

	static final int INIT_TOTAL = 0;
	static final int INIT_FIRST_ROUND = 1;
	static final int INIT_NEWROUND = 2;
	public static final int ACTION_HU = 6;

	public static int MAX_CARD_NUM_144 = 144; // 总计144张牌
	public static int MAX_CARD_NUM_120 = 120; // 总计136张牌
	public static int MAX_CARD_NUM_136 = 136; // 总计136张牌
	public static int MAX_CARD_NUM_108 = 108; // 总计108张牌

	public static int HAND_MJ_MAX = 14;
	public static int MAX_BLOCK_NUM = 4;

	public static int GAME_END_NORMAL = 0;
	public static int GAME_END_PASS = 1;
	public static int GAME_END_ESCAPE = 2;
	public static int GAME_END_MAXROUND = 3;
	public static int GAME_END_DISMISS = 4;

	public static int GANG_BUPAI = 0xFE; // 杠牌补牌
	public static int RESERVED_PAI = 0xFE; // 杠牌补牌

	public static int FALSE = 0;
	public static int TRUE = 1;

	public static int INVALID_CARD =  0xFF; // 无效的牌
	public static int INVALID_SEAT_VALUE =  0xFF;
	public static int INVALID_CHAIR =  0xFF;

	public static int GS_FREE = 0; // 空闲状态
	public static int GS_PLAYING = 100; // 游戏状态

	// 公共宏定义
	// 结束原因
	public static int GER_NORMAL = 0x00; // 常规结束
	public static int GER_DISMISS = 0x01; // 游戏解散
	public static int GER_USER_LEFT = 0x02; // 用户离开

	//////////////////////////////////////////////////////////////////////////
	// 命令码定义

	public static int SUB_S_GAME_START = 100; // 游戏开始

	public static int SUB_S_ADD_GOLD = 101; // 加注结果
	public static int SUB_S_GIVE_UP = 102; // 放弃跟注
	public static int SUB_S_SEND_CARD = 103; // 发牌消息
	public static int SUB_S_GAME_END = 104; // 游戏结束
	// public static int SUB_S_KAIPAI = 105 ; //开牌 //add
	// public static int SUB_S_KANPAI = 106 ; //看牌 //add
	public static int SUB_S_OVER = 107; // add

	public static int SUB_GF_SCENE = 111;
	public static int SUB_GF_SIT = 112;
	public static int SUB_GF_STANDUP = 113;
	//////////////////////////////////////////////////////////////////////////
	// 消息结构体
	// 用户状态定义
	public static int US_NULL = 0x00; // 没有状态
	public static int US_READY = 0x01; // 同意状态
	public static int US_PLAY = 0x02; // 游戏状态

	public static int US_FREE = 0x10; // 站立状态
	public static int US_SIT = 0x11; // 坐下状态
	public static int US_LOOKON = 0x12; // 旁观状态
	public static int US_OFFLINE = 0x13;
	public static int US_LEAVE = 0x14;

	public static int GAME_KIND = 13;
	// public static int INIT_TOTAL = 0; // 牌局全部清空
	// public static int INIT_FIRST_ROUND = 1; // 牌局全部清空
	// public static int INIT_NEWROUND = 2; // 为了下一把初始化一些东西

	public static int CountArray(int by[]) {
		return by.length;
	}


	public static int sizeof(tagUserReport[] m_kReport) {
		return m_kReport.length;
	}

	public static int countof(int[] by,int by2) {
		int cntCount = 0;
		for (int i = 0; i < by.length; i++) {
			if (by[i] == by2) {
				cntCount++;
			}
		}
		return cntCount;
	}
	public static int countof(int[] by,int by2,int count) {
		int cntCount = 0;
		for (int i = 0; i < count; i++) {
			if (by[i] == by2) {
				cntCount++;
			}
		}
		return cntCount;
	}	
	public static int replace(int[] by,int by1,int by2) {
		int cntCount = 0;
		for (int i = 0; i < by.length; i++) {
			if (by[i] == by1) {
				by[i] = by2;
				cntCount++;
			}
		}
		return cntCount;
	}
	public static int replace(int[] by,int by1,int by2,int count) {
		int cntCount = 0;		
		if(count > 0)
		{
			for (int i = 0; i < by.length; i++) {
				if (by[i] == by1) {
					by[i] = by2;
					cntCount++;
					count--;
					if(count<= 0)
					{
						break;
					}
				}
			}
		}

		return cntCount;
	}	
	public static void CopyMemory(int[] by, int by2, int length) {
		for (int i = 0; i < length; i++) {
			by[i] = by2;
		}
	}

	public static void CopyMemory(int[] by, int[] by2, int length) {
		for (int i = 0; i < length; i++) {
			by[i] = by2[i];
		}
	}

	public static void memcpy(int[] by, int[] by2, int length) {
		for (int i = 0; i < length; i++) {
			by[i] = by2[i];
		}
	}
	public static int memcmp(int[] by, int[] by2, int length) {
		for (int i = 0; i < length; i++) {
			if(by[i] != by2[i])
			{
				return -1;
			}
		}
		return 0;
	}
	public static void memset(int[] by, int by2, int length) {
		for (int i = 0; i < length; i++) {
			by[i] = by2;
		}
	}

	public static Random rd = new Random();
	public static int bai = 33;

	public static int rand() {
		return rd.nextInt(  1024 );
	}

	public static int rand(int i, int j, int factor) {
		return rd.nextInt(j - i) + i;
	}

	public static int sizeof(IServerUserItem[] m_pIUserItem) {
		return m_pIUserItem.length;
	}

	public static int sizeof(long[] m_LookOnUserID) {
		return m_LookOnUserID.length;
	}

	public static void memset(long[] by, int by2, int length) {
		for (int i = 0; i < length; i++) {
			by[i] = (long) by2;
		}

	}

	public static void memcpy(HU hu, HU hu2) {
		for(int i=0;i<4;i++)
		{
			hu.block[i].first = hu2.block[i].first;
			hu.block[i].style = hu2.block[i].style;
			hu.block[i].origValue = hu2.block[i].origValue;
		}
		hu.jiangMj = hu2.jiangMj;
	}

	public static final int BLOCK_NULL = 0; // 无
	public static final int BLOCK_CHI = 1; // 吃牌结构
	public static final int BLOCK_SUN = 2; // 顺序结构
	public static final int BLOCK_PENG = 3; // 碰子结构,3个相同
	public static final int BLOCK_KE = 4; // 刻子结构,3个相同,非碰
	public static final int BLOCK_GANG = 5; // 杠子结构,4个相同
	public static final int BLOCK_AN_GANG = 6; // 暗杠
	public static final int BLOCK_BU_GANG = 7; // 补杠

	public static final int ZHUANG_JIA = 0;

	public static final int PI_HU = 0;
	public static final int WU_GUI = 1;
	public static final int MA_PAI = 2;
	public static final int DIAN_PAO = 3;
	public static final int DIAN_GANG = 4;
	public static final int MING_GANG = 5;
	public static final int BU_GANG = 6;
	public static final int AN_GANG = 7;
	
	
	

	public static final int TUI_DAO_HU = 0;	
	public static final int PENG_PENG_HU = 1;	
	public static final int QI_DUI_ZI = 2;
	public static final int HAO_HUA_QI_DUI_ZI = 3;
	public static final int SHUANG_HAO_HUA_QI_DUI_ZI = 4;
	public static final int SAN_HAO_HUA_QI_DUI_ZI = 5;
	public static final int QING_YI_SE = 6;
	public static final int KA_WU_XING = 7;
	public static final int SI_DA_XUE_SHI = 8;
	public static final int XIAO_SAN_YUAN = 9;
	public static final int DA_SAN_YUAN = 10;
	public static final int MING_SI_GUI = 11;
	public static final int AN_SI_GUI = 12;
	public static final int GANG_SHANG_PAO = 13;
	public static final int LIANG_DAO_HU = 14;
	public static final int GANG_KAI = 15;
	public static final int MING_PAI = 16;
	public static final int QIANG_GANG = 17;
	public static final int HAI_DI_LAO_YUE = 18;
	public static final int SHOU_ZHUA_YI = 19;
	public static final int QING_YI_SE_PENG_PENG_HU = 25;
	public static final int QING_YI_SE_QI_DUI_ZI = 26;
	public static final int QING_YI_SE_MING_SE_GUI = 27;
	public static final int QING_YI_SE_AN_SE_GUI = 28;
	
	public static final int MINGPAI = 29;
	public static final int HAI_DI_LAO_YUE_PAO = 30;
	public static final int MING_GANG_PAI = 31;
	public static final int AN_GANG_PAI = 32;
	public static final int DAXUESHI_PAI = 33;
	public static final int QING_YI_SE_SHOU_ZHUA_YI = 34;
	public static final int QING_YI_SE_KA_WU_XING = 35;
	
	public static final int TIAN_HU = 40;
	public static final int DI_HU = 41;
	public static final int REN_HU = 42;
	public static final int TIAN_TING = 43;
	
	public static final int ZI_MO_HU = 50;
	public static final int DUI_DUI_HU =51;
	public static final int QUAN_YAO_JIU = 52;
	public static final int SI_GUI_YI = 53;
	public static final int HONG_YI_SE = 54;
	public static final int CHONG_TIAN = 55;
	
	public static int atoi(String string) {
		try {
			return Integer.parseInt(string);
		} catch (Exception e) {

		}
		return 0;
	}

	public static int sizeof(SSeatInfo[] m_seatInfo) {
		return m_seatInfo.length;
	}

	public static void memset(SSeatInfo[] m_seatInfo, int by2, int sizeof) {
		for (int i = 0; i < m_seatInfo.length; i++) {
			m_seatInfo[i] = new SSeatInfo();
		}
	}

	public static long time(Object object) {
		return System.currentTimeMillis();
	}

	public static Object sizeof(HU hu) {
		return null;
	}



	public static int sizeof(int[] byParam) {
		return byParam.length;
	}


	static final int ACTION_WITH_ROBOT = 100;

	static final int ACTION_GIVE_UP = 0;
	static final int ACTION_MO_PAI = 0;
	static final int ACTION_CHU_PAI = 1;
	static final int ACTION_CHI = 2;
	static final int ACTION_PENG = 3;
	static final int ACTION_GANG = 4;
	static final int ACTION_TING = 5; // 出牌，不用于权限，仅用于立直一发
	static final int ACTION_HUANPAI = 10;
	static final int ACTION_GANG_BUPAI = 11;
	static final int ACTION_BU_HUA = 12;

	
	
	public static void Sort(int byHandCard[]) {
		for (int i = 0; i < byHandCard.length - 1; i++) {
			for (int j = i; j < byHandCard.length; j++) {
				int x = byHandCard[i];
				int y = byHandCard[j];
				if (x > y) {
					int tempvalue = byHandCard[i];
					byHandCard[i] = byHandCard[j];
					byHandCard[j] = tempvalue;
				}
			}
		}
	}

	public static final int[] FENGS= new int[]{27,	28,	29,	30};
}
